package 正则表达式;

import java.util.Locale;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.net.URLCodec;

import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;

//import org.junit.jupiter.api.Test;
import java.math.BigInteger;
import java.util.Random;

//import java.io.IOException;
import java.io.InputStreamReader;

public class exec {
   public static void main(String[] args) throws Exception{
       Outer outer = new Outer("Nested"); // 实例化一个Outer
       Outer.Inner inner = outer.new Inner(); // 实例化一个Inner
       inner.hello();
       
       
       List<String> list1 = List.of();//空集合
       List<String> list2 = Collections.emptyList();//空集合
       List<String> list3 = List.of("apple");//单元素集合
       List<String> list4 = Collections.singletonList("apple");//单元素集合
       Set<String> set1=Set.of("apple");
       Map<String, Integer> map1 =Map.of("apple",2);
       Map<String, Integer> map = new HashMap<>();
       
       map.put("111",111);
       map.put("222",222);
       //Integer in=map.put("222", 333);
       //System.out.println(in);
       File f=new File("d:\\newpath");
       Boolean bo=f.mkdir();
       System.out.println(bo);
       String str="d:\\ags/";
       str=str.replace("/", f.separator);
       System.out.println(str);
       
       
       System.out.println(System.getProperty("java.class.path"));
       System.out.println(exec.class.getResource(""));
       System.out.println(exec.class.getResource("/"));
       System.out.println(exec.class.getClassLoader().getResource(""));
       
       System.out.println(System.currentTimeMillis());//获取当前时间戳
       LocalDate d = LocalDate.now(); // 当前日期
       LocalTime t = LocalTime.now(); // 当前时间
       LocalDateTime dt = LocalDateTime.now(); // 当前日期和时间
       System.out.println(d); // 严格按照ISO 8601格式打印  2023-06-08
       System.out.println(t); // 严格按照ISO 8601格式打印  09:19:31.407627300
       System.out.println(dt); // 严格按照ISO 8601格式打印  2023-06-08T09:19:31.407627300
       
       LocalDateTime start = LocalDateTime.of(2019, 11, 19, 8, 15, 0);
       LocalDateTime end = LocalDateTime.of(2020, 1, 9, 19, 25, 30);
       Duration d1 = Duration.between(start, end);//两个时刻之间的时间间隔
       System.out.println(d1); // PT1235H10M30S

       Period p = LocalDate.of(2019, 11, 19).until(LocalDate.of(2020, 1, 9));//两个日期之间的天数
       System.out.println(p); // P1M21D
       
       ZonedDateTime zdt = ZonedDateTime.now();
       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm ZZZZ");
       System.out.println(formatter.format(zdt));

       DateTimeFormatter zhFormatter = DateTimeFormatter.ofPattern("yyyy MMM dd EE HH:mm", Locale.CHINA);
       System.out.println(zhFormatter.format(zdt));

       DateTimeFormatter usFormatter = DateTimeFormatter.ofPattern("E, MMMM/dd/yyyy HH:mm", Locale.US);
       System.out.println(usFormatter.format(zdt));
       
       String encoded = URLEncoder.encode("-_.* abcd中文!", StandardCharsets.UTF_8);
       System.out.println(encoded);//-_.*+abcd%E4%B8%AD%E6%96%87%21 空格：+
       
       MessageDigest md = MessageDigest.getInstance("SHA-1");
       // 反复调用update输入数据:
       md.update("Hello".getBytes("UTF-8"));
       md.update("World".getBytes("UTF-8"));
       byte[] result = md.digest(); // 20 bytes: db8ac1c259eb89d4a131b253bacfca5f319d54f2
       System.out.println(new BigInteger(1,result).toString(16));
       
       BigInteger b = new BigInteger("10000000", 2); // 输入2进制转10进制
       System.out.println(b); // 输出 8
       BigInteger bx = new BigInteger("FF", 16); // 输入16进制转10进制
       System.out.println(bx); // 输出 255
       System.out.println(Math.pow(2, 3));
       
    // byte数组转为16进制字符串
       String hex = Hex.encodeHexString("123".getBytes());
       System.out.println("hex---"+hex);
       // 16进制字符串解码
       byte[] src = Hex.decodeHex(hex);
       System.out.println(new String(src));
       
       File ff = new File("d:test.txt");
       System.out.println(ff.getPath());
       System.out.println(ff.getAbsolutePath());
       System.out.println(ff.getCanonicalPath());
       
       Integer n = Integer.valueOf(123);//new Integer(123);
       
       boolean b1 = n instanceof Integer; // true，因为n是Integer类型
       boolean b2 = n instanceof Number; // true，因为n是Number类型的子类
       
       boolean b3 = n.getClass() == Integer.class; // true，因为n.getClass()返回Integer.class
       //boolean b4 = n.getClass() == Number.class; // false，因为Integer.class!=Number.class
       //用instanceof不但匹配指定类型，还匹配指定类型的子类。而用==判断class实例可以精确地判断数据类型，但不能作子类型比较。
       
/*
    String smtp = "smtp.office365.com";
    // 登录用户名:
    String username = "jxsmtp101@outlook.com";
    // 登录口令:
    String password = "********";
    // 连接到SMTP服务器587端口:
    Properties props = new Properties();
    props.put("mail.smtp.host", smtp); // SMTP主机名
    props.put("mail.smtp.port", "587"); // 主机端口号
    props.put("mail.smtp.auth", "true"); // 是否需要用户认证
    props.put("mail.smtp.starttls.enable", "true"); // 启用TLS加密
    // 获取Session实例:
    Session session = Session.getInstance(props, new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    // 设置debug模式便于调试:
    session.setDebug(true);
*/

   }
}

class Outer {
   private String name;

   Outer(String name) {
       this.name = name;
   }

   class Inner {
       void hello() {
           System.out.println("Hello, " + Outer.this.name);
       }
   }
}